<?php 
class Keyword extends CI_Controller {
	
	function Keyword()
	{
		parent::__construct();
		$this->load->library('session');
		$this->load->library('form_validation');
		$this->load->library('encrypt');                
                $this->load->model('musers');
                $this->load->model('mmaster');
                $this->load->model('mkeyword');
		#$this->is_logged_in();
		#$this->mjadwal->saveLog();
	}
	
	function is_logged_in()
	{
		$is_logged_in = $this->session->userdata('is_logged_in');
		if(!isset($is_logged_in) || $is_logged_in != true)
		{
			redirect(base_url() .'index.php/login');
		}		
	}
        
        function generate($proses="",$id="") {
            $data['template'] = "shell/smooth";         
            $data['main_view'] = 'f-keyword';	
            $data['proses'] = $proses;
            $data['id']	= $id;
            $data['hasil'] = "";        
            $data['hasil2'] = "";   
            
            #inisialisasi elemen form yang harus diisi		
		$this->form_validation->set_rules('tanggal', 'Tanggal', 'required');
                
                $this->form_validation->set_error_delimiters('<li>','</li>');
		$this->form_validation->set_message('required', 'Kolom <b>%s</b> harus diisi.');
                
            if($this->input->post("delete")) {
                $data['hasil2'] = $this->mkeyword->deleteKeyword($this->input->post("tanggal"));
            }else if($this->input->post("submit")) {
                if ($this->form_validation->run() != FALSE){
                        // masukkan data di sini
                        if($this->input->post("tanggal") <> "") {
                            $valid_date = $this->input->post("tanggal");
                        }else {
                            $valid_date = "CURRENT_DATE()";
                        }
                        $data['hasil'] = $this->mkeyword->generate($valid_date);

                        //$this->session->set_flashdata('message', 'Data Berhasil dimasukkan');
                        //redirect(base_url()."index.php/master/usermanagement");
                }	
            }
            $this->load->view($data['template'],$data);
        }
        
        public function read() {
            if($this->input->post("view")) {
		echo json_encode( $this->mkeyword->getKeyword($this->input->post("tanggal")) );
            }else {
                echo json_encode( $this->mkeyword->getKeyword() );
            }
	}

}

?>
